﻿using System;

namespace NetTopologySuite.Index.IntervalRTree
{
	public class IntervalRTreeBranchNode<T> : IntervalRTreeNode<T>
	{
		public IntervalRTreeBranchNode(IntervalRTreeNode<T> n1, IntervalRTreeNode<T> n2)
		{
			this._node1 = n1;
			this._node2 = n2;
			this.BuildExtent(this._node1, this._node2);
		}

		private void BuildExtent(IntervalRTreeNode<T> n1, IntervalRTreeNode<T> n2)
		{
			base.Min = System.Math.Min(n1.Min, n2.Min);
			base.Max = System.Math.Max(n1.Max, n2.Max);
		}

		public override void Query(double queryMin, double queryMax, IItemVisitor<T> visitor)
		{
			if (!base.Intersects(queryMin, queryMax))
			{
				return;
			}
			if (this._node1 != null)
			{
				this._node1.Query(queryMin, queryMax, visitor);
			}
			if (this._node2 != null)
			{
				this._node2.Query(queryMin, queryMax, visitor);
			}
		}

		private readonly IntervalRTreeNode<T> _node1;

		private readonly IntervalRTreeNode<T> _node2;
	}
}
